package keating;

import java.awt.Color;
import java.util.List;

import javax.swing.JPanel;

/**
 * 功能名   画板
 * 类描述	
 * @author  Keating
 */
public class PanelDrawer extends JPanel {

    /*-------------------类成员定义--------------------*/
    private static final long serialVersionUID = 1L;
    /**
     * 宽度
     */
    private int width;
    /**
     * 高度
     */
    private int height;
    /*-------------------构造方法--------------------*/
    public PanelDrawer(){
        super();
        this.setBackground(Color.white);
    }
    /*-------------------业务逻辑--------------------*/
    
    /**
     * 缩放
     */
    public void zoom() {
        // 背景界面缩放,在JScroPane上缩放,setSize()并无效果
        javax.swing.GroupLayout resultPanel1Layout = new javax.swing.GroupLayout(this);
        this.setLayout(resultPanel1Layout);
        resultPanel1Layout.setHorizontalGroup(
            resultPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, width, Short.MAX_VALUE)
        );
        resultPanel1Layout.setVerticalGroup(
            resultPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, height, Short.MAX_VALUE)
        );
        this.repaint();
    }
    
    /**
     * 调用者传递要画的线段和文本过来
     */
    public void sendContainers(List<OneBlogPanel> blogs) {
        this.removeAll();// 清除所有组件
        
        for(OneBlogPanel blog : blogs) {
            this.add(blog);
            if(blog.getHeight()+blog.getY()>height){
                height = blog.getHeight()+blog.getY();
            }
            if(blog.getWidth()+blog.getX()>width){
                width = blog.getWidth()+blog.getX();
            }
        }
        
        this.zoom();
    }
    /*-------------------GET&SET--------------------*/
    
}
